//
//  HMPresentationCell.swift
//  HealthMonitoring
//
//  Created by YTYanK on 2018/10/10.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

class HMPresentationCell: HMTableViewCell {
    let pre_image = UIImageView()
    let pre_title = UILabel()
    let pre_describe = UILabel()
    let pre_date = UILabel()
   
    override func setupViews(view: UIView) {
        view.addSubview(pre_image)
        view.addSubview(pre_title)
        view.addSubview(pre_describe)
        view.addSubview(pre_date)
        
        pre_image.leadingAlign(view: view, predicate: "10")
        pre_image.centerYAlign(view: view)
        pre_image.widthConstrain(predicate: "90")
        pre_image.heightConstrain(predicate: "90")
        pre_image.img(url: "")
        
        pre_title.leadingHorizontally(view: pre_image, predicate: "10")
        pre_title.topAlign(view: pre_image, predicate: "0")
        pre_title.trailingAlign(view: view)
        pre_title.heightConstrain(predicate: "28")
//        pre_title.backgroundColor = .red
        pre_title.text = "xbbbbbbbb"
        
        pre_describe.leadingHorizontally(view: pre_image, predicate: "10")
        pre_describe.topVertically(view: pre_title, predicate: "3")
        pre_describe.trailingAlign(view: view)
        pre_describe.heightConstrain(predicate: "28")
//        pre_describe.backgroundColor = .blue
        pre_describe.text = "xxbxxxxxx"
        
        pre_date.leadingHorizontally(view: pre_image, predicate: "10")
        pre_date.topVertically(view: pre_describe, predicate: "3")
        pre_date.trailingAlign(view: view)
        pre_date.heightConstrain(predicate: "28")
//        pre_date.backgroundColor = .green
        pre_date.text = "2018-10-12"
        
    }
    
    override func setJson(json: JSON) {
        let imsgeUrl = configure.shareConfigure.IP_diagonal + json["images"][0].stringValue
        let dateStr: String = json["createDate"].stringValue
        
        pre_image.img(url: imsgeUrl)
        pre_title.text = json["title"].stringValue
        pre_describe.text = json["mark"].stringValue
        pre_date.text = String(dateStr.prefix(10))
    }
}
